package com.augurit.wf.bi.convert;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.augurit.common.util.lang.DateUtils;
import com.augurit.wf.bi.web.form.WfTemplateElementRefForm;
import com.augurit.wf.common.entity.WfTemplateElementRef;

public class WfTemplateElementRefConvertor {
	public static WfTemplateElementRefForm convertVoToForm(WfTemplateElementRef entity) {
		if(entity != null) {
			WfTemplateElementRefForm form = new WfTemplateElementRefForm();
			form.setId(entity.getId());
			form.setTemplateId(entity.getTemplateId());
			form.setElementId(entity.getElementId());
			return form;
		}else
			return null;
	}
	
	public static void convertFormToVo(WfTemplateElementRefForm form, WfTemplateElementRef entity) {
		if(entity != null && form != null) {
			entity.setId(form.getId());
			entity.setTemplateId(form.getTemplateId());
			entity.setElementId(form.getElementId());
		}
	}
	
	public static List<WfTemplateElementRefForm> convertVoListToFormList(List<WfTemplateElementRef> wfTemplateElementRefList) {
		if(wfTemplateElementRefList != null && wfTemplateElementRefList.size() > 0) {
			List<WfTemplateElementRefForm> wfTemplateElementRefFormList = new ArrayList();
			for(int i=0; i<wfTemplateElementRefList.size(); i++) {
				wfTemplateElementRefFormList.add(convertVoToForm(wfTemplateElementRefList.get(i)));
			}
			return wfTemplateElementRefFormList;
		}
		return null;
	}
	
	public static List<Map> convertVoListToMapList(List<WfTemplateElementRef> wfTemplateElementRefList) {
		if(wfTemplateElementRefList != null && wfTemplateElementRefList.size() > 0) {
			List<Map> mapList = new ArrayList();
			for(int i=0; i<wfTemplateElementRefList.size(); i++) {
				WfTemplateElementRef entity = wfTemplateElementRefList.get(i);
				Map<String, String> map = new HashMap();

				map.put("id", entity.getId() == null ? "" : entity.getId().toString());
				map.put("templateId", entity.getTemplateId() == null ? "" : entity.getTemplateId().toString());
				map.put("elementId", entity.getElementId() == null ? "" : entity.getElementId().toString());
				
				mapList.add(map);
			}
			return mapList;
		}
		return null;
	}
	
	public static List<WfTemplateElementRef> convertFormListToVoList(List<WfTemplateElementRefForm> wfTemplateElementRefFormList) {
		if(wfTemplateElementRefFormList != null && wfTemplateElementRefFormList.size() > 0) {
			List<WfTemplateElementRef> wfTemplateElementRefList = new ArrayList();
			for(int i=0; i<wfTemplateElementRefFormList.size(); i++) {
				WfTemplateElementRef wfTemplateElementRef = new WfTemplateElementRef();
				convertFormToVo(wfTemplateElementRefFormList.get(i), wfTemplateElementRef);
				wfTemplateElementRefList.add(wfTemplateElementRef);
			}
			return wfTemplateElementRefList;
		}
		return null;
	}
}